package com.ctshk.sapp.insurance.controller;


import com.ctshk.common.dto.Result;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.insurance.dto.InsuranceBusinessPageDTO;
import com.ctshk.rpc.insurance.dto.InsuranceDTO;
import com.ctshk.rpc.insurance.dto.InsuranceGroupPageDTO;
import com.ctshk.rpc.insurance.dto.InsuranceProductDTO;
import com.ctshk.rpc.insurance.req.*;
import com.ctshk.rpc.insurance.req.tp.OfferReq;
import com.ctshk.rpc.insurance.service.IInsuranceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * <p>
 * 保险资源 前端控制器
 * </p>
 *
 * @author wangcy
 * @since 2021-01-26
 */
@Api(value="资源中心保险产品", tags="资源中心保险产品")
@RestController
@RequestMapping("/insurance")
public class InsuranceController extends BaseController {

    @DubboReference
    private IInsuranceService iInsuranceService;


    @ApiOperation(value = "保险产品管理列表查询", notes = "保险产品管理列表查询")
    @GetMapping(value = "/query-list")
    public Result<PageResponse<InsuranceProductDTO>> queryList(@ModelAttribute InsuranceProductReq insuranceProductReq) {
        return Result.success(iInsuranceService.queryList(insuranceProductReq));
    }

    @ApiOperation(value = "保险产品列表查询(团专用)", notes = "保险产品管理列表查询(团专用)")
    @PostMapping(value = "/group/page")
    public Result<PageResponse<InsuranceGroupPageDTO>> queryList(@RequestBody @Valid InsuranceGroupPageReq insuranceGroupPageReq) {
        return Result.success(iInsuranceService.queryGroupList(insuranceGroupPageReq));
    }

    @ApiOperation(value = "保险产品列表查询(自由行专用)", notes = "保险产品管理列表查询(自由行专用)")
    @PostMapping(value = "/business/page")
    public Result<List<InsuranceBusinessPageDTO>> queryList(@RequestBody @Valid InsuranceBusinessPageReq insuranceBusinessPageReq) {
        Long userId = getCurrentUser().getId();
        return Result.success(iInsuranceService.queryBusinessList(insuranceBusinessPageReq,userId));
    }

    @ApiOperation(value = "保险售卖状态批量修改", notes = "保险售卖状态批量修改")
    @PostMapping(value = "/batch-update-status")
    public Result<Long> batchUpdateStatus(@RequestBody InsuranceStatusReq req) {
        iInsuranceService.batchUpdateStatus(req);
        return Result.success(req.getIds().get(0).longValue());
    }

    @ApiOperation(value = "保险详情查询", notes = "保险详情查询")
    @GetMapping(value = "/detail")
    public Result<InsuranceDTO> detail(@RequestParam(value = "id", required = true) Long id) {
        return Result.success(iInsuranceService.detail(id));
    }

    @ApiOperation(value = "保险详情修改", notes = "保险详情修改")
    @PostMapping(value = "/update")
    public Result<Long> updateDetail(@RequestBody @Valid InsuranceReq insuranceReq) {
        iInsuranceService.updateDetail(insuranceReq);
        return Result.success(insuranceReq.getId());
    }


    /*@ApiOperation(value = "承保", notes = "保险下单")
    @PostMapping(value = "/accept")
    public Result updateDetail(@RequestBody List<AcceptReq> accept) throws Exception{
        return iInsuranceService.accept(accept);
    }*/

    @ApiOperation(value = "承保", notes = "保险下单(服务器内部调用)")
    @PostMapping(value = "/sendProposalContent")
    public Result sendProposalContent(@RequestBody InsuranceUnderwritingReq insuranceUnderwritingReq) throws Exception{
        return Result.success(iInsuranceService.sendProposalContent(insuranceUnderwritingReq));
    }

    /*@ApiOperation(value = "报价", notes = "报价")
    @PostMapping(value = "/offer")
    public Result offer(@RequestBody OfferReq offerReq) throws Exception{
        return iInsuranceService.offer(offerReq);
    }*/

    /*@ApiOperation(value = "退保", notes = "保险退保")
    @PostMapping(value = "/cancel")
    public Result cancel(@RequestBody List<CancelReq> cancelReq) throws Exception{
        return iInsuranceService.cancel(cancelReq);
    }*/

    @ApiOperation(value = "报价", notes = "报价")
    @PostMapping(value = "/offerProposalContent")
    public Result sendProposalContent(@RequestBody OfferReq offerReq) throws Exception{
        return Result.success(iInsuranceService.acciQuotation(offerReq));
    }
}
